// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.randomizedWorld.randomizedBuilding;

import zombie.core.Rand;
import zombie.iso.BuildingDef;
import zombie.iso.IsoCell;
import zombie.iso.IsoGridSquare;
import zombie.iso.IsoObject;
import zombie.iso.IsoWorld;

public final class RBBar extends RandomizedBuildingBase {
    @Override
    public void randomizeBuilding(BuildingDef def) {
        IsoCell isoCell = IsoWorld.instance.CurrentCell;

        for (int int0 = def.x - 1; int0 < def.x2 + 1; int0++) {
            for (int int1 = def.y - 1; int1 < def.y2 + 1; int1++) {
                for (int int2 = 0; int2 < 8; int2++) {
                    IsoGridSquare isoGridSquare = isoCell.getGridSquare(int0, int1, int2);
                    if (isoGridSquare != null && this.roomValid(isoGridSquare)) {
                        for (int int3 = 0; int3 < isoGridSquare.getObjects().size(); int3++) {
                            IsoObject isoObject = isoGridSquare.getObjects().get(int3);
                            if (isoObject.getSprite() != null
                                && isoObject.getSprite().getName() != null
                                && (isoObject.getSprite().getName().equals("recreational_01_6") || isoObject.getSprite().getName().equals("recreational_01_7"))
                                )
                             {
                                if (Rand.NextBool(3)) {
                                    this.addWorldItem("PoolBall", isoGridSquare, isoObject);
                                }

                                if (Rand.NextBool(3)) {
                                    this.addWorldItem("Poolcue", isoGridSquare, isoObject);
                                }
                            } else if (isoObject.isTableSurface() && Rand.NextBool(2)) {
                                if (Rand.NextBool(3)) {
                                    this.addWorldItem("Cigarettes", isoGridSquare, isoObject);
                                    if (Rand.NextBool(2)) {
                                        this.addWorldItem("Lighter", isoGridSquare, isoObject);
                                    }
                                }

                                int int4 = Rand.Next(7);
                                switch (int4) {
                                    case 0:
                                        this.addWorldItem("WhiskeyFull", isoGridSquare, isoObject);
                                        break;
                                    case 1:
                                        this.addWorldItem("Wine", isoGridSquare, isoObject);
                                        break;
                                    case 2:
                                        this.addWorldItem("Wine2", isoGridSquare, isoObject);
                                        break;
                                    case 3:
                                        this.addWorldItem("BeerCan", isoGridSquare, isoObject);
                                        break;
                                    case 4:
                                        this.addWorldItem("BeerBottle", isoGridSquare, isoObject);
                                }

                                if (Rand.NextBool(3)) {
                                    int int5 = Rand.Next(7);
                                    switch (int5) {
                                        case 0:
                                            this.addWorldItem("Crisps", isoGridSquare, isoObject);
                                            break;
                                        case 1:
                                            this.addWorldItem("Crisps2", isoGridSquare, isoObject);
                                            break;
                                        case 2:
                                            this.addWorldItem("Crisps3", isoGridSquare, isoObject);
                                            break;
                                        case 3:
                                            this.addWorldItem("Crisps4", isoGridSquare, isoObject);
                                            break;
                                        case 4:
                                            this.addWorldItem("Peanuts", isoGridSquare, isoObject);
                                    }
                                }

                                if (Rand.NextBool(4)) {
                                    this.addWorldItem("CardDeck", isoGridSquare, isoObject);
                                }
                            }
                        }

                        if (Rand.NextBool(20)
                            && isoGridSquare.getRoom() != null
                            && isoGridSquare.getRoom().getName().equals("bar")
                            && isoGridSquare.getObjects().size() == 1
                            && Rand.NextBool(8)) {
                            this.addWorldItem("Dart", isoGridSquare, null);
                        }
                    }
                }
            }
        }
    }

    public boolean roomValid(IsoGridSquare sq) {
        return sq.getRoom() != null && "bar".equals(sq.getRoom().getName());
    }

    @Override
    public boolean isValid(BuildingDef def, boolean force) {
        return def.getRoom("bar") != null && def.getRoom("stripclub") == null || force;
    }

    public RBBar() {
        this.name = "Bar";
        this.setAlwaysDo(true);
    }
}
